/**
 * Copyright 2012 Fonfon.Fenceer
 * All rights reserved.
 * 
 * @project 
 * @author Fonfon.Fenceer
 * @version 1.0
 * @data 2012-3-14
 */
package com.guidecaptain.java.action;

import java.util.List;

import net.sf.json.JSONObject;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.guidecaptain.core.base.action.BaseAction;
import com.guidecaptain.core.common.CookieManager;
import com.guidecaptain.java.model.pojo.Guide;
import com.guidecaptain.java.model.pojo.Guidefm;
import com.guidecaptain.java.model.vo.GuideVO;
import com.guidecaptain.java.service.GuideService;
import com.guidecaptain.java.service.GuidefmService;

/**
 * 
 * @author fenceer
 */
@Controller
@Scope("prototype")
public class GuideAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Logger LOG = Logger.getLogger(GuideAction.class);

	@Autowired
	private GuideService guideService;
	@Autowired
	private GuidefmService guidefmService;

	private GuideVO guideVO = new GuideVO();

	/**
	 * 添加导游领队信息
	 */
	public String insertGuide() {
		CookieManager cookieManager = new CookieManager(getRequest(), getResponse());
		int role = Integer.parseInt(cookieManager.getCookieValue("role"));
		if (role > 3) {
			int guideId = this.guideService.insertGudie(guideVO);
			if (guideId > 0) {
				guideVO.setGuideId(guideId);
				return "insert";
			} else {
				return "fail";
			}
		} else {
			return "fail";
		}
	}
	
	/**
	 * 更新导游领队信息
	 */
	public String updateGudie() {
		return null;

	}
	
	/**
	 * 查询导游领队个人信息
	 */
	public String queryGuide() {
		Guide guide = guideService.queryGuideById(guideVO.getGuideId());
		try {
			PropertyUtils.copyProperties(guideVO, guide);
		} catch (Exception e) {
			LOG.error(e);

			return "fail";
		}
		List<Guidefm> guidefms=guidefmService.queryGuidefmList(guideVO.getGuideId());
		guideVO.setGuidefms(guidefms);
		return "guideinfo";
	}
	
	/**
	 * 查询导游领队信息列表
	 */
	public String queryGuideList() {
		guideVO = guideService.queryGuideList(guideVO);
		return "guideList";
	}
	
	/**
	 * 获得导游名字列表
	 * @return
	 */
	public String getGuidenameList() {
		JSONObject jsonObject = guideService.getGuideNameList(guideVO);

		setJsonObject(jsonObject);
		return JSON;
	}

	/**
	 * @param
	 * @return
	 */
	@Override
	public Object getModel() {

		return guideVO;
	}

}
